package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.AddressBean;
import com.ptmall.app.bean.CouponBean;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class CouponAdapter extends BaseAdapter {

    private Context mContext;
    private List<CouponBean> mDataList;
    private LayoutInflater mLayoutInflater;

    public CouponAdapter(Context context, List<CouponBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<CouponBean> list){
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(mDataList == null){
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_coupon,  parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        CouponBean bean = mDataList.get(position);

        viewHolder.youxiaoqi.setText("有效期："+bean.stop_time);
        viewHolder.tiaojian.setText(bean.style_name);
        if(bean.type.equals("1")){
            viewHolder.quantype.setText("通用券");
        }else {
            viewHolder.quantype.setText("指定券");
        }
        viewHolder.manprice.setText("满"+bean.man_use+"可用");
        viewHolder.price.setText("￥"+bean.money);
        return convertView;
    }

    class ViewHolder {

        TextView youxiaoqi,tiaojian,quantype,manprice,price;

        ViewHolder(View view) {
            youxiaoqi = (TextView) view.findViewById(R.id.youxiaoqi);
            tiaojian = (TextView) view.findViewById(R.id.tiaojian);
            quantype = (TextView) view.findViewById(R.id.quantype);
            manprice = (TextView) view.findViewById(R.id.manprice);
            price = (TextView) view.findViewById(R.id.price);
        }
    }

}
